
package com.c2dm.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.c2dm.data.AuthenticationUtil;
import com.c2dm.data.SecureStorage;

@SuppressWarnings("serial")
public class AuthenticationServlet extends HttpServlet
{

	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException 
	{
		doPost(req, resp);
	}

	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException 
	{
        // get token from google
		String token = AuthenticationUtil.getToken(SecureStorage.USER,SecureStorage.PASSWORD);
		
		resp.setContentType("text/plain");
		PrintWriter writer = resp.getWriter();
		
		/*
		//if (token != null & token.length() > 0)
		{
			// Save data
			Entity entity = new Entity("token", "mytoken");
			entity.setProperty("authkey", token);
			DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
			datastore.put(entity);
			//write token back
			writer.write("Response: " + token + "\n");
		}*/
		
		
		//write token back
		writer.write("Response: " + token + "\n");
		
		writer.write("Registration process finished.\n");
	}
}